import requests
import os
import pandas as pd

url = 'https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/'
html = requests.get(url).content
df_list = pd.read_html(html)
for df in df_list:
    df ['Until'] = df['Until'].replace('-', None)

    df['Since'] = pd.to_numeric(df['Since'])
    df['Until'] = pd.to_numeric(df['Until'])
    deprecated_count = df[df['Stage'].str.contains('Deprecated')]
    if len(deprecated_count) > 0:
        # TODO: Find out if anyone uses this
        # df.to_json('deprecated.json', orient='records', indent=2)
        print("Skipping deprecated table")
    else:
        feature_gates_json = df.to_json(orient='records', indent=2)

go_template = """// This file is autogenerated. DO NOT EDIT
package views

var FeatureList = `{json}`
""".format(json=feature_gates_json)

dir = os.path.dirname(__file__)
filename = os.path.join(dir, '..', 'pkg', 'plugin', 'views', 'feature_gates.go')

with open(filename, 'w') as go_file:
    print(go_template, file=go_file)